var express = require("express");
var router = express.Router();
var db = require("../model/index");

/* 全部订单接口*/
router.get("/getwxorders", function (req, res, next) {
    let mysql = `SELECT t1.color,t1.spjg,t1.size,t1.name,t2.type,t1.img
    FROM goods AS t1 LEFT JOIN order_type AS t2 ON t1.typeid=t2.id `;
    db(mysql, function (err, data) {
        if (err) {
            return res.json({
                code: 500,
                msg: "订单数据失败",
            });
        }
        res.json({
            code: 200,
            msg: "订单数据成功",
            data: data,
        });
    });
});
/* 售后订单接口*/
router.get("/get_after_orders", function (req, res, next) {
    let mysql = `SELECT t1.color,t1.spjg,t1.size,t1.name,t2.type,t1.img
    FROM goods AS t1 LEFT JOIN order_type AS t2 ON t1.typeid=t2.id  WHERE TYPE='售后'`;
    db(mysql, function (err, data) {
        if (err) {
            return res.json({
                code: 500,
                msg: "订单数据失败",
            });
        }
        res.json({
            code: 200,
            msg: "订单数据成功",
            data: data,
        });
    });
});
/* 已完成订单数据接口*/
router.get("/Completed_order", function (req, res, next) {
    let mysql = `SELECT t1.color,t1.spjg,t1.size,t1.name,t2.type,t1.img
    FROM goods AS t1 LEFT JOIN order_type AS t2 ON t1.typeid=t2.id  WHERE TYPE='已完成'`;
    db(mysql, function (err, data) {
        if (err) {
            return res.json({
                code: 500,
                msg: "订单数据失败",
            });
        }
        res.json({
            code: 200,
            msg: "订单数据成功",
            data: data,
        });
    });
});
/*待评价订单接口*/
router.get("/evaluated", function (req, res, next) {
    let mysql = `SELECT t1.color,t1.spjg,t1.size,t1.name,t2.type,t1.img
    FROM goods AS t1 LEFT JOIN order_type AS t2 ON t1.typeid=t2.id  WHERE TYPE='待评价'`;
    db(mysql, function (err, data) {
        if (err) {
            return res.json({
                code: 500,
                msg: "订单数据失败",
            });
        }
        res.json({
            code: 200,
            msg: "订单数据成功",
            data: data,
        });
    });
});
/*待收货订单接口*/
router.get("/received", function (req, res, next) {
    let mysql = `SELECT t1.color,t1.spjg,t1.size,t1.name,t2.type,t1.img
    FROM goods AS t1 LEFT JOIN order_type AS t2 ON t1.typeid=t2.id  WHERE TYPE='待收货'`;
    db(mysql, function (err, data) {
        if (err) {
            return res.json({
                code: 500,
                msg: "订单数据失败",
            });
        }
        res.json({
            code: 200,
            msg: "订单数据成功",
            data: data,
        });
    });
});
/*待收货订单接口*/
router.get("/pedding", function (req, res, next) {
    let mysql = `SELECT t1.color,t1.spjg,t1.size,t1.name,t2.type,t1.img
    FROM goods AS t1 LEFT JOIN order_type AS t2 ON t1.typeid=t2.id  WHERE TYPE='待付款'`;
    db(mysql, function (err, data) {
        if (err) {
            return res.json({
                code: 500,
                msg: "订单数据失败",
            });
        }
        res.json({
            code: 200,
            msg: "订单数据成功",
            data: data,
        });
    });
});

module.exports = router;
